﻿using Architecture.CrossCutting.Common.Logging;
using Architecture.CrossCutting.LoggingEntities.Models;
using Architecture.CrossCutting.Web.WCF;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.CrossCutting.LoggingEntities.Logger
{
    public class WcfClientLogger : IGenericLogger<Web.WCF.WcfClientLog>
    {

        public WcfClientLogger()
        {
            //Mapper.Initialize(
            //    cfg => cfg.CreateMap<WcfClientLog, WcfClientLog>()
            //           .ForMember(l => l.Started, opt => opt.MapFrom(src => src.PipeLineStarted))
            //           .ForMember(l => l.Finished, opt => opt.MapFrom(src => src.PipeLineEnded))
            //           .ForMember(l => l.RequestDuration, opt => opt.MapFrom( src => src.PipeLineDuration))
            //);
        }


        public void WriteError(string message, Web.WCF.WcfClientLog data, Exception ex)
        {
            throw new NotImplementedException();
        }

        public void WriteInfo(string message, Web.WCF.WcfClientLog data)
        {
            var result = Mapper.Map<WcfClientLog>(data);

            using (var loggingService = new LoggingServiceContext())
            {
                loggingService.WcfClientLogs.Add(result);
                Int32 count = loggingService.SaveChanges();
            }

        }
    }
}
